from PySide6.QtWidgets import QPushButton
from PySide6.QtCore import Signal

class BehaviorButton(QPushButton):
    clicked_with_count = Signal()

    def __init__(self, title):
        super().__init__(f"{title} (0)")
        self.title = title
        self.count = 0
        self.clicked.connect(self._handle_click)

    def _handle_click(self):
        if self.count < 9:
            self.count += 1
            self.update_count()

    def update_count(self, btn_count=None):
        if btn_count is not None:
            self.count = btn_count
        self.setText(f"{self.title} ({self.count})")
        self.clicked_with_count.emit()